package dice.sinanya.db.properties.system;

import dice.sinanya.db.tools.DbUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import static dice.sinanya.system.MessagesSystem.loginInfo;
import static dice.sinanya.tools.getinfo.GetMessagesProperties.entitySystemProperties;

/**
 * @author SitaNya
 * 日期: 2019-06-15
 * 电子邮箱: sitanya@qq.com
 * 维护群(QQ): 162279609
 * 有任何问题欢迎咨询
 * 类说明: 查询KP主群类，刷写到静态变量中，只在静态变量中找不到时才需要使用
 */
public class SelectSystemProperties {
    private static final Logger log = LogManager.getLogger(SelectSystemProperties.class.getName());


    public SelectSystemProperties() {
        //        初始化时无需逻辑
    }

    /**
     * 刷新kp主群设定到静态变量中，只有静态变量中找不到某人的kp主群记录时才会使用
     */
    public void flushProperties() {
        try (Connection conn = DbUtil.getConnection()) {
            int i = 0;
            //language=MySQL
            String sql = "select * from test.systemProperties where botId=?";
            try (PreparedStatement ps = conn.prepareStatement(sql)) {
                ps.setString(1, String.valueOf(loginInfo.getLoginId()));
                try (ResultSet set = ps.executeQuery()) {
                    while (set.next()) {
                        entitySystemProperties.setBotStart(set.getString("botStart"));
                        entitySystemProperties.setBotAlreadyStart(set.getString("botAlreadyStart"));
                        entitySystemProperties.setBotStop(set.getString("botStop"));
                        entitySystemProperties.setBotAlreadyStop(set.getString("botAlreadyStop"));
                        entitySystemProperties.setBotExit(set.getString("botExit"));
                        entitySystemProperties.setBotInfo(set.getString("botInfo"));
                        entitySystemProperties.setBookCard(set.getString("bookCard"));
                        entitySystemProperties.setBookRp(set.getString("bookRp"));
                        entitySystemProperties.setBookKp(set.getString("bookKp"));
                        entitySystemProperties.setBookMake(set.getString("bookMake"));
                        entitySystemProperties.setManyRollsFormat(set.getString("manyRollsFormat"));
                        entitySystemProperties.setDiceTimesTooBig(set.getString("diceTimesTooBig"));
                        entitySystemProperties.setSetPropFormat(set.getString("setPropFormat"));
                        entitySystemProperties.setSetHelp(set.getString("setHelp"));
                        entitySystemProperties.setNotFoundSkill(set.getString("NotFoundSkill"));
                        entitySystemProperties.setSetPropSuccess(set.getString("setPropSuccess"));
                        entitySystemProperties.setDndInitIsEmtpy(set.getString("dndInitIsEmtpy"));
                        entitySystemProperties.setClrDndInit(set.getString("clrDndInit"));
                        entitySystemProperties.setNeedKpGroup(set.getString("needKpGroup"));
                        entitySystemProperties.setCantInPrivate(set.getString("cantInPrivate"));
                        entitySystemProperties.setOnlyManager(set.getString("onlyManager"));
                        entitySystemProperties.setAlreadyOpen(set.getString("alreadyOpen"));
                        entitySystemProperties.setAlreadyClose(set.getString("alreadyClose"));
                        entitySystemProperties.setNotFoundLog(set.getString("notFoundLog"));
                        entitySystemProperties.setReadLock(set.getString("readLock"));
                        entitySystemProperties.setDeleteOpenLog(set.getString("deleteOpenLog"));
                        entitySystemProperties.setSanCheck(set.getString("sanCheck"));
                        entitySystemProperties.setAntagonizeOver(set.getString("antagonizeOver"));
                        entitySystemProperties.setAntagonizeFirstSuccess(set.getString("antagonizeFirstSuccess"));
                        entitySystemProperties.setAntagonizeSecondSuccess(set.getString("antagonizeSecondSuccess"));
                        entitySystemProperties.setAntagonizeAllFailed(set.getString("antagonizeAllFailed"));
                        entitySystemProperties.setAntagonizeDraw(set.getString("antagonizeDraw"));
                        entitySystemProperties.setSymptom(set.getString("symptom"));
                        entitySystemProperties.setEnSuccess(set.getString("enSuccess"));
                        entitySystemProperties.setEnFailed(set.getString("enFailed"));
                        entitySystemProperties.setHiddenDice(set.getString("hiddenDice"));
                        entitySystemProperties.setTeamIsEmpty(set.getString("teamIsEmpty"));
                        entitySystemProperties.setTeamMemberEnIsEmpty(set.getString("teamMemberEnIsEmpty"));
                        entitySystemProperties.setAppendLog(set.getString("appendLog"));
                        entitySystemProperties.setCreateLog(set.getString("createLog"));
                        entitySystemProperties.setCantEmptyLogName(set.getString("CantEmptyLogName"));
                        entitySystemProperties.setSanCheckFumble(set.getString("sanCheckFumble"));
                        entitySystemProperties.setSanCheckCriticalSuccess(set.getString("sanCheckCriticalSuccess"));
                        entitySystemProperties.setSanCheckSuccess(set.getString("sanCheckSuccess"));
                        entitySystemProperties.setSanCheckFailure(set.getString("sanCheckFailure"));
                        entitySystemProperties.setCRITICAL_SUCCESS(set.getString("CRITICAL_SUCCESS"));
                        entitySystemProperties.setEXTREME_SUCCESS(set.getString("EXTREME_SUCCESS"));
                        entitySystemProperties.setHARD_SUCCESS(set.getString("HARD_SUCCESS"));
                        entitySystemProperties.setSUCCESS(set.getString("SUCCESS"));
                        entitySystemProperties.setFAILURE(set.getString("FAILURE"));
                        entitySystemProperties.setFUMBLE(set.getString("FUMBLE"));
                        entitySystemProperties.setPublicMode(set.getBoolean("public"));
                        entitySystemProperties.setRunning(set.getBoolean("running"));
                        entitySystemProperties.setHelpInfo(set.getString("helpInfo"));
                        entitySystemProperties.setZookeeper(set.getBoolean("zookeeper"));
                        entitySystemProperties.setRollInfo(set.getString("rollInfo"));
                        entitySystemProperties.setAutoUpdate(set.getBoolean("autoUpdate"));
                        entitySystemProperties.setCustomSearchUpdate(set.getString("customSearchUpdate"));
                        entitySystemProperties.setCustomSearchInsert(set.getString("customSearchInsert"));
                        entitySystemProperties.setDeckListShow(set.getString("deckListShow"));
                        entitySystemProperties.setDiceListShow(set.getString("diceListShow"));
                        entitySystemProperties.setClueInsert(set.getString("clueInsert"));
                        entitySystemProperties.setClueRemove(set.getString("clueRemove"));
                        entitySystemProperties.setClueClear(set.getString("clueClear"));
                        entitySystemProperties.setSetKp(set.getString("setKp"));
                        entitySystemProperties.setMonsterSet(set.getString("monsterSet"));
                        entitySystemProperties.setMonsterNeedKp(set.getString("monsterNeedKp"));
                        entitySystemProperties.setMonsterSetDone(set.getString("monsterSetDone"));
                        entitySystemProperties.setMonsterFormatError(set.getString("monsterFormatError"));
                        entitySystemProperties.setMonsterClear(set.getString("monsterClear"));
                        entitySystemProperties.setMonsterClearDone(set.getString("monsterClearDone"));
                        entitySystemProperties.setMonsterShow(set.getString("monsterShow"));
                        entitySystemProperties.setNoticeInsert(set.getString("noticeInsert"));
                        entitySystemProperties.setNoticeEmpty(set.getString("noticeEmpty"));
                        entitySystemProperties.setNoticeShow(set.getString("noticeShow"));
                        entitySystemProperties.setNoticeAgree(set.getString("noticeAgree"));
                        entitySystemProperties.setNoticeNotFound(set.getString("noticeNotFound"));
                        entitySystemProperties.setNoticeRefuse(set.getString("noticeRefuse"));
                        entitySystemProperties.setNpcInsertForKp(set.getString("npcInsertForKp"));
                        entitySystemProperties.setNpcNeedKp(set.getString("npcNeedKp"));
                        entitySystemProperties.setNpcInsert(set.getString("npcInsert"));
                        entitySystemProperties.setNpcFormatError(set.getString("npcFormatError"));
                        entitySystemProperties.setNpcDelete(set.getString("npcDelete"));
                        entitySystemProperties.setNpcClear(set.getString("npcClear"));
                        entitySystemProperties.setNpcShow(set.getString("npcShow"));
                        entitySystemProperties.setRoleAlreadyLock(set.getString("roleAlreadyLock"));
                        entitySystemProperties.setRoleTooLong(set.getString("roleTooLong"));
                        entitySystemProperties.setRoleDefault(set.getString("roleDefault"));
                        entitySystemProperties.setRoleUpdate(set.getString("roleUpdate"));
                        entitySystemProperties.setRoleChange(set.getString("roleChange"));
                        entitySystemProperties.setRoleShow(set.getString("roleShow"));
                        entitySystemProperties.setRoleCantDelete(set.getString("roleCantDelete"));
                        entitySystemProperties.setRoleCantDeleteByLock(set.getString("roleCantDeleteByLock"));
                        entitySystemProperties.setRoleDelete(set.getString("roleDelete"));
                        entitySystemProperties.setRoleChangeDefault(set.getString("roleChangeDefault"));
                        entitySystemProperties.setRoleLock(set.getString("roleLock"));
                        entitySystemProperties.setRoleLockDone(set.getString("roleLockDone"));
                        entitySystemProperties.setRoleUnlock(set.getString("roleUnlock"));
                        entitySystemProperties.setRoleNotLock(set.getString("roleNotLock"));
                        entitySystemProperties.setRoleChangeName(set.getString("roleChangeName"));
                        entitySystemProperties.setRoleNotChoose(set.getString("roleNotChoose"));
                        entitySystemProperties.setSendMustInsert(set.getString("sendMustInsert"));
                        entitySystemProperties.setSendAlready(set.getString("sendAlready"));
                        entitySystemProperties.setAnswerFormatError(set.getString("answerFormatError"));
                        entitySystemProperties.setDiceDefault(set.getString("diceDefault"));
                        entitySystemProperties.setDiceFormat(set.getString("diceFormat"));
                        entitySystemProperties.setTeamFormatError(set.getString("teamFormatError"));
                        entitySystemProperties.setTeamInsert(set.getString("teamInsert"));
                        entitySystemProperties.setTeamRemove(set.getString("teamRemove"));
                        entitySystemProperties.setTeamClear(set.getString("teamClear"));
                        entitySystemProperties.setTeamCall(set.getString("teamCall"));
                        entitySystemProperties.setTeamNotChooseRole(set.getString("teamNotChooseRole"));
                        entitySystemProperties.setTeamShow(set.getString("teamShow"));
                        entitySystemProperties.setTeamProp(set.getString("teamProp"));
                        entitySystemProperties.setTeamDesc(set.getString("teamDesc"));
                        entitySystemProperties.setTeamEn(set.getString("teamEn"));
                        entitySystemProperties.setTeamRename(set.getString("teamRename"));
                        entitySystemProperties.setTeamLock(set.getString("teamLock"));
                        entitySystemProperties.setTeamLockChange(set.getString("teamLockChange"));
                        entitySystemProperties.setRbStr(set.getString("rbStr"));
                        entitySystemProperties.setRpStr(set.getString("rpStr"));
                        entitySystemProperties.setRiStr(set.getString("riStr"));
                        entitySystemProperties.setInitStr(set.getString("initStr"));
                        entitySystemProperties.setInitRm(set.getString("initRm"));
                        entitySystemProperties.setInitSet(set.getString("initSet"));
                        entitySystemProperties.setrResult(set.getString("rResult"));
                        entitySystemProperties.setRhStr(set.getString("rhStr"));
                        entitySystemProperties.setRhForSkill(set.getString("rhForSkill"));
                        entitySystemProperties.setHistoryStr(set.getString("historyStr"));
                        entitySystemProperties.setLogOffDone(set.getString("logOffDone"));
                        entitySystemProperties.setLogGetForOpen(set.getString("logGetForOpen"));
                        entitySystemProperties.setManNotFound(set.getString("manNotFound"));
                        entitySystemProperties.setDndQKError(set.getString("dndQKError"));
                        entitySystemProperties.setMakeCardTooMore(set.getString("makeCardTooMore"));
                        entitySystemProperties.setCnModError(set.getString("cnModError"));
                        entitySystemProperties.setCnModNumberZero(set.getString("cnModNumberZero"));
                        entitySystemProperties.setCnModPageNumTooBig(set.getString("cnModPageNumTooBig"));
                        entitySystemProperties.setCustomAlreadyExist(set.getString("customAlreadyExist"));
                        entitySystemProperties.setCustomFormat(set.getString("customFormat"));
                        entitySystemProperties.setFireAlreadyInPage(set.getString("fireAlreadyInPage"));
                        entitySystemProperties.setFireRd(set.getString("fireRd"));
                        entitySystemProperties.setFireSkill(set.getString("fireSkill"));
                        entitySystemProperties.setGetNameTimes(set.getString("getNameTimes"));
                        entitySystemProperties.setGetNameTimesTooMore(set.getString("getNameTimesTooMore"));
                        entitySystemProperties.setInitSetFormat(set.getString("initSetFormat"));
                        entitySystemProperties.setInputNameTimesForNumber(set.getString("inputNameTimesForNumber"));
                        entitySystemProperties.setNotAdminPower(set.getString("notAdminPower"));
                        entitySystemProperties.setNotEnableBySimple(set.getString("notEnableBySimple"));
                        entitySystemProperties.setNotEnable(set.getString("notEnable"));
                        entitySystemProperties.setNotEnableInGroup(set.getString("notEnableInGroup"));
                        entitySystemProperties.setNotFoundGroup(set.getString("notFoundGroup"));
                        entitySystemProperties.setRollCantInZero(set.getString("rollCantInZero"));
                        entitySystemProperties.setSetAlgorithmType(set.getString("setAlgorithmType"));
                        entitySystemProperties.setSetRuleFormat(set.getString("setRuleFormat"));
                        entitySystemProperties.setWodCheckMaxCantInA(set.getString("wodCheckMaxCantInA"));
                        entitySystemProperties.setWodCheckNotIsOne(set.getString("wodCheckNotIsOne"));
                        entitySystemProperties.setWodToMore(set.getString("wodToMore"));
                        i++;
                    }
                }
                if (i == 0) {
                    new InsertProperties().insertProperties(entitySystemProperties);
                }
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
    }
}
